<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>活动详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../static/css/typo.css" th:href="@{/css/typo.css}">
    <link rel="stylesheet" href="../static/css/animate.css" th:href="@{/css/animate.css}">
    <link rel="stylesheet" href="../static/lib/prism/prism.css" th:href="@{/lib/prism/prism.css}">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css" th:href="@{/lib/tocbot/tocbot.css}">
    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>
<div class="row" th:replace="_fragments :: menu(0)"></div>

<!--中间内容-->
<div id="waypoint" class="m-container-small m-padded-tb-big animated fadeIn">
    <div class="ui container">
        <!--头部-->
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="https://unsplash.it/100/100?image=1005" alt="" class="ui avatar image">
                    <div class="content"><a href="#" class="header" th:text="${detail.lead.name}">Tina</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i><label th:text="${detail.publishTime}"></label>
                </div>
                <div class="item">
                    <i class="eye icon"></i><label th:text="${detail.view}"></label>
                </div>
            </div>
        </div>
        <!--图片区域-->
        <div class="ui attached segment">
            <img src="https://unsplash.it/800/450?image=1005" alt="" class="ui rounded image">
        </div>
        <!--内容-->
        <div class="ui attached padded segment">
            <div class="ui right aligned basic segment">
                <div class="ui orange basic label">原创</div>
            </div>
            <h2 class="ui center aligned header" th:text="${detail.title}">关于刻意练习的清单</h2>
            <br>
            <div id="content" class="m-padded-lr-responsive m-padded-tb-large white-space:pre-wrap"
                 th:text="${detail.content}">
                周日下午3点小区集合
            </div>

            <div style="text-align: center">
                活动开始时间：<label th:text="${detail.startTime}"></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                活动结束时间: <label th:text="${detail.endTime}"></label>
            </div>

            <!--标签-->
            <div class="m-padded-lr-responsive">
                <div class="ui basic teal left pointing label" th:text="${detail.type.name}">旅游</div>
            </div>
            <div class="ui button" onclick="cancel(this.id)" th:id="${detail.id}" th:if="${tip!=null}" title="点击取消报名"
                 style="margin-left: 44%">活动已报名
            </div>
            <div class="ui primary button" onclick="enroll(this.id)" th:id="${detail.id}" th:if="${tip==null}"
                 title="点击报名活动" style="margin-left: 44%">活动报名
            </div>

        </div>
        <!--留言区域-->
        <div class="ui bottom attached segment" id="good">
            <!--留言区域列表-->
            <div id="comment-container" class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%;">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.user.name}">Matt</span>
                                    <div class="ui mini basic teal left pointing label m-padded-mini"
                                         th:if="${comment.adminComment}">负责人
                                    </div>
                                </a>
                                <div class="metadata">
                                    <span class="date" th:text="${comment.startTime}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:attr="data-commentid=${comment.id},data-commentname=${comment.user.name}"
                                       onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="https://unsplash.it/100/100?image=1005">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.user.name}">小红</span>
                                            <div class="ui mini basic teal left pointing label m-padded-mini"
                                                 th:if="${reply.adminComment}">负责人
                                            </div>
                                            &nbsp;<span th:text="|@ ${reply.parentComment.user.name}|"
                                                        class="m-teal">@ 小白</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date" th:text="${reply.startTime}">Today at 5:42PM</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">
                                            How artistic!
                                        </div>
                                        <div class="actions">
                                            <a class="reply" data-commentid="1" data-commentname="Matt"
                                               th:attr="data-commentid=${reply.id},data-commentname=${reply.user.name}"
                                               onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="comment-form" class="ui form">
                <input type="hidden" name="activity.id" th:value="${detail.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field  m-margin-bottom-small m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i
                                class="edit icon"></i>发布
                        </button>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<br>
<br>

<!--底部footer-->
<footer class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin">Email：lirenmi@163.com</a>
                    <a href="#" class="item m-text-thin">QQ：865729312</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">Blog</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客、会分享关于编程、写作、思考相关的任何内容，希望可以给来到这儿的人有所帮助...</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2016 - 2017 Lirenmi Designed by Lirenmi</p>
    </div>

</footer>
<th:block th:replace="_fragments :: script">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
</th:block>

<script th:inline="javascript">
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
        popup: $('.payQR.popup'),
        on: 'click',
        position: 'bottom center'
    });

    function enroll(id) {
        $.ajax({
            url: "/activity/enroll/" + id,
            type: "POST",
            success: function (result) {
                if (result.code === 200) {
                    alert("报名成功");
                    window.location.reload();
                } else if (result.code === 500) {
                    alert("账号未登录")
                } else {
                    alert("错误，请联系管理员");
                }
            }
        });
    }

    function cancel(id) {
        $.ajax({
            url: "/activity/cancel/" + id,
            async: false,
            type: "POST",
            success: function (result) {
                if (result.code === 200) {
                    alert("报名取消成功");
                    window.location.reload();
                } else {
                    alert("错误，请联系管理员");
                }
            }
        });
    }

    $(function () {
        var url = "/comments/" + [[${detail.id}]];
        $('#comment-container').load(url);
    });


    $('#commentpost-btn').click(function () {
        var con = $("[name='content']").val();
        if (con.length === 0) {
            alert("请输入");
        } else {
            postData();
        }
    });

    function postData() {
        $("#comment-container").load("/comments", {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "activity.id": $("[name='activity.id']").val(),
            "content": $("[name='content']").val()
        }, function () {
            var url = "/comments/" + [[${detail.id}]];
            $('#comment-container').load(url);
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentname = $(obj).data('commentname');
        $("[name='content']").attr("placeholder", "@" + commentname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }


    /*

        //保存时的方法
        var text =$("#synopsis").val();	//获取textarea输入的值
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); //把里面的回车和空格转换成html类型


        //保存后显示在textarea的方法
        var text =result.synopsis;	//获取数据库查出的字符串
        var des = (text.replace(/&nbsp;/g, " ")).replace(/<br\/>/g, "\r")	//将html类型转换成对应的空格和回车


        //显示在div中
        var text = result.synopsis;//获取数据库查出的字符串
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, '&nbsp;'); //转换格式
        $("#synopsis").append(des);
    */


</script>
</body>
</html>
